#pragma once
#include "HashTable.h"

namespace hash_bucket
{
	template<typename K,typename V,typename Hash = HashFunc<K>>
	class unordered_map
	{
		struct KeyOfMap
		{
			const K& operator()(const pair<K,V>& kv) {
				return kv.first;
			}
		};
	public:
		typedef typename hash_bucket::HashTable<K, pair<const K,V>, KeyOfMap,Hash>::Iterator iterator;
		typedef typename hash_bucket::HashTable<K, pair<const K,V>, KeyOfMap,Hash>::ConstIterator const_iterator;

		iterator begin()
		{
			return _hs.Begin();
		}
		const_iterator begin() const
		{
			return _hs.Begin();
		}

		iterator end()
		{
			return _hs.End();
		}
		const_iterator end() const
		{
			return _hs.End();
		}

		pair<iterator,bool> insert(const pair<K,V>& kv)
		{
			return _hs.insert(kv);
		}

		bool erase(const K& Key)
		{
			return _hs.erase(Key);
		}

		iterator Find(const K& key)
		{
			return _hs.Find(key);
		}

		V& operator[](const K& key)
		{
			pair<iterator, bool> ret = insert(make_pair(key, V()));
			return ret.first->second;
		}

	private:
		hash_bucket::HashTable<K, pair<const K, V>, KeyOfMap,Hash> _hs;
	};
}
